<?php


namespace api\controller;


use common\controller\VerifyController;
use common\service\ProjectReviewOptionsService;
use common\validate\ProjectReviewOptions;
use support\ErrorCode;
use think\Request;

class ProjectReviewOptionsController extends VerifyController
{

    /**
     * @var \common\service\ProjectReviewOptionsService
     */
    private $projectReviewOptionsService;

    public function __construct()
    {
        parent::__construct();
        $this->projectReviewOptionsService = ProjectReviewOptionsService::getInstance();
    }

    /**
     * 批量创建项目成员
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function save(Request $request)
    {
        $param = $request->param();


        $validate = new ProjectReviewOptions();
        if (!empty($param['data']['json'])) {
            $validate->scene('SaveProjectReviewOptionsItem');
            foreach ($param['data']['json'] as $item) {
                if (!$validate->check($item)) {
                    throw_strack_exception($validate->getError(), ErrorCode::REQUEST_PARAM_ERROR);
                }
                if (!is_string($item["step_category_ids"])) {
                    throw_strack_exception("data.json must be a string", ErrorCode::REQUEST_PARAM_ERROR);
                }
            }
        }

        if (is_string($param['data']['json'])) {
            throw_strack_exception("data.json must be a array", ErrorCode::REQUEST_PARAM_ERROR);
        }

        $res = $this->projectReviewOptionsService->save($param['data']);
        return json(success_response("", $res));
    }

    /**
     * 多个查询
     * @param \think\Request $request
     * @return \think\Response
     * @throws \think\Exception
     */
    public function selectProjectReviewOptions(Request $request)
    {
        $param = $request->param()["param"];
        $res = $this->projectReviewOptionsService->selectProjectReviewOptions($param);
        return json(success_response("", $res));
    }
}